import json
numbers=['dd','aa','cc']
filename='username.json'
# json.dump()存储数据列表、字典到文件中
with open(filename,'w') as file_obj:
    json.dump(numbers,file_obj)

# json.load()将列表读取到内存中
try:
    with open(filename) as f_obj:
        print(1111)
        number = json.load(f_obj)
except FileNotFoundError:
    print('None')
else:
    print(number)



#  重构
def get_stored_username():
    filename = 'username.json'
    try:
        with open(filename) as f_obj:
            username = json.load(f_obj)
    except FileNotFoundError:
        return None
    else:
        return username


def get_new_username():
    username = input("What is your name? ")
    filename = 'username.json'
    with open(filename, 'w') as f_obj:
        json.dump(username, f_obj)
        return username


def greet_user():
    username = get_stored_username()
    if username:
        print("Welcome back, " + username + "!")
    else:
        username = get_new_username()
        print("We'll remember you when you come back, " + username + "!")


greet_user()